<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
      <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
        <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
      <!-- 导出  -->
    </div>
    <!--表单组件-->
    <eForm ref="form" :is-add="isAdd"/>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" border size="small" style="width: 100%;">
      <el-table-column prop="id" label="异常编号" width="70"/>
      <el-table-column prop="title" label="异常标题"/>
      <el-table-column prop="created" label="异常时间" width="140"/>
      <el-table-column
        :filters="filterList"
        :filter-method="filterHandler"
        prop="method"
        label="异常方法"
        width="200"/>
      <el-table-column prop="parameter" label="异常参数"/>
      <el-table-column label="操作" width="50" align="center">
        <template slot-scope="scope">
          <el-button size="mini" circle type="success" icon="el-icon-search" @click="edit(scope.row.text)"/>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>

    <el-dialog :visible.sync="dialogVisible" title="提示" width="30%">
      <span>{{ value }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogVisible = false">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import {} from '@/api/gcbException'
import eForm from './form'
export default {
  components: { eForm },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      dialogVisible: false,
      value: '',
      queryTypeOptions: [
        { key: 'id', display_name: '异常编号' },
        { key: 'title', display_name: '异常标题' },
        { key: 'created', display_name: '异常时间' },
        { key: 'text', display_name: '异常内容' },
        { key: 'method', display_name: '异常方法' }
      ],
      filterList: [
        { text: 'reg', value: 'reg' },
        { text: 'wxLogin', value: 'wxLogin' },
        { text: '其他', value: '其他' }
      ]
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    checkPermission,
    beforeInit() {
      this.url = 'api/gcbException'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      const type = query.type
      const value = query.value
      if (type && value) { this.params[type] = value }
      return true
    },
    edit(val) {
      const _this = this.$refs.form
      _this.text = val
      _this.dialog = true
    },
    filterHandler(value, row, column) {
      console.log(value, row, column)
      const property = column['property']
      if (row[property] === 'wxLogin' || row[property] === 'reg') {
        return row[property] === value
      } else {
        return row[property]
      }
    }
  }
}
</script>

<style scoped>

</style>
